﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sofire.DataComm.Net.Async
{
    
    /// <summary>
    /// 表示异步套接字操作。包含 <see cref="Sofire.DataComm.Net.Async.SocketAsyncEventArgsClient"/> 的内容，并且包含当前连接的客户端相关信息。
    /// </summary>
    internal class SocketAsyncEventArgsServer : SocketAsyncEventArgsClient, IRemoteClientEventArgs
    {
        internal readonly AsyncSocketServer AsyncServerSocket;
        internal readonly RemoteClient ClientInfo;
        internal readonly SocketAsyncEventArgsServer SendAsyncEventArgs;

        public override bool IsConnected
        {
            get
            {
                return !this.ClientInfo.IsShutdown;
            }
        }

        public SocketAsyncEventArgsServer(AsyncSocketServer asyncServerSocket)
        {
            this.AsyncServerSocket = asyncServerSocket;
            this.ClientInfo = new RemoteClient(this, asyncServerSocket);
            SendAsyncEventArgs = new SocketAsyncEventArgsServer(this.AsyncServerSocket, this.ClientInfo);
        }

        private SocketAsyncEventArgsServer(AsyncSocketServer asyncServerSocket, RemoteClient clientInfo)
            : base(false, true)
        {
            this.AsyncServerSocket = asyncServerSocket;
            this.ClientInfo = clientInfo;
        }

        IRemote IRemoteClientEventArgs.ClientInfo
        {
            get { return this.ClientInfo; }
        }
    }

}
